package systemServer.general;

import gateway.Gateway;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;

import payment.IPaymentMethod;
import systemServer.members.FindMember;
import systemServer.reproduction.FindSong;
import systemServer.reproduction.Song;
import dao.MemberDAO;
import dto.Assembler;
import dto.MemberDTO;
import dto.RecomendationDTO;
import dto.SongDTO;
import dto.SongInfoDTO;

public class SystemFacade extends UnicastRemoteObject implements IConnection {
//	private static SystemFacade instance;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1287481242135810112L;
	
	private IPaymentMethod iPaymentMethod;
	public SystemFacade(String [] args) throws RemoteException {
		super();

		iPaymentMethod = Gateway.getInstance(args[3]); 
		//System.out.println("\nSystem Facade\n");
		//System.out.println(FindSong.getArtistSongs("John Lennon"));
	

	}
//	public static synchronized SystemFacade getInstance (String [] args) throws RemoteException{
//		if (instance == null){
//			instance = new SystemFacade(args);
//		}
//		return instance;
//	}
	@Override
	public void addFavourite(SongInfoDTO song) {
	
	}

	@Override
	public void addPermanent(SongInfoDTO song) {
		
	}

	@Override
	public List<SongInfoDTO> getFavouriteList() {
		return null;
	}

	@Override
	public List<SongInfoDTO> getPermanentList() {
		return null;
	}

	@Override
	public SongDTO play(SongInfoDTO sid, MemberDTO md) {
		Song song = FindSong.getSong(sid.getId());
		try {
			iPaymentMethod.addExpected(song.getPricePerPlay());
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return song.play(FindMember.getMember(md.getUsername())); 
	}

	@Override
	public String playRecomendation(SongInfoDTO sid, MemberDTO md) {
		return null;
	}

	@Override
	public void recomendSong(SongInfoDTO song, MemberDTO targetMember) {
		
	}

	@Override
	public List<SongInfoDTO> searchArtist(String artist) {
//		Member m = FindMember.getMember("gonzalo");
		List<Song> list = FindSong.getArtistSongs(artist);
		List<SongInfoDTO> sid = new ArrayList<SongInfoDTO>();
		for (Song song : list){
			SongInfoDTO songInfo = Assembler.createSongInfoDTO(song);
			sid.add(songInfo);
		}
		
//				Song s1 = new Song(1, "Imagine", "John Lennon", 183, 59985356400000L, 0.99, "Imagine there's no heaven\nIt's easy if you try\nNo hell below us\nAbove us only sky\nImagine all the people\nLiving for today...\n\nImagine there's no countries\nIt isn't hard to do\nNothing to kill or die for\nAnd no religion too\nImagine all the people\nLiving life in peace...\n\nYou may say I'm a dreamer\nBut I'm not the only one\nI hope someday you'll join us\nAnd the world will be as one\n\nImagine no possessions\nI wonder if you can\nNo need for greed or hunger\nA brotherhood of man\nImagine all the people\nSharing all the world...\n\nYou may say I'm a dreamer\nBut I'm not the only one\nI hope someday you'll join us\nAnd the world will live as one\n", "I'm the song Imagine of John Lennon");
//				Song s2 = new Song(2, "Norwegian wood", "John Lennon", 175, 50000000000000L, 0.59, "I once had a girl\nOr should I say she once had me\nShe showed me her room\nIsn't it good Norwegian wood?\nShe asked me to stay\nAnd she told me to sit anywhere\nSo I looked around\nAnd I noticed there wasn't a chair\nI sat on a rug biding my time\ndrinking her wine\nWe talked until two and then she said\n\"it's time for bed\"\n\nShe told me she worked\nin the morning and started to laugh\nI told her I didn't\nand crawled off to sleep in the bath\nAnd when I awoke I was alone\nThis bird had flown\nSo I lit a fire\nIsn't it good Norwegian wood?\n", "I'm the song Norwegian wood of John Lennon");
//				Song s3 = new Song(3, "Revolution", "John Lennon", 190, 78959694959696L, 0.47, "You say you want a revolution\nWell you know\nWe all want to change the world\nYou tell me that it's evolution\nWell you know\nWe all want to change the world\nBut when you talk about destruction\nDon't you know you can count me out\nDon't you know it's gonna be alright\nAlright Alright\nYou say you got a real solution\nWell you know\nWe'd all love to see the plan\nYou ask me for a contribution\nWell you know\nWe're doing what we can\nBut when you want money for people with minds that hate\nAll I can tell you is brother you have to wait\nDon't you know it's gonna be alright\nAlright Alright\n\nYou say you'll change the constitution\nWell you know\nWe all want to change your head\nYou tell me it's the institution\nWell you know\nYou better free your mind instead\nBut if you go carrying pictures of Chairman Mao\nYou ain't going to make it with anyone anyhow\nDon't you know know it's gonna be alright\nAlright Alright\n", "I'm the song Revolution of John Lennon");
//				Song s4 = new Song(4, "In my life", "John Lennon", 200, 90000000000000L, 1.00, "There are places I remember\nAll my life, though some have changed\nSome forever not for better\nSome have gone and some remain\nAll these places had their moments\nWith lovers and friends\nI still can recall\nSome are dead and some are living\nIn my life I've loved them all\n\nBut of all these friends and lovers\nthere is no one compares with you\nAnd these memories lose their meaning\nWhen I think of love as something new\nThough I know I'll never lose affection\nFor people and things that went before\nI know I'll often stop and think about them\nIn my life I love you more\n\nThough I know I'll never lose affection\nFor people and things that went before\nI know I'll often stop and think about them\nIn my life I love you more\nIn my life I love you more", "I'm the song In my life  of John Lennon");
//				Song s5 = new Song(5, "Instant karma", "John Lennon", 230, 70000000000000L, 0.80, "Instant Karma's gonna get you\nGonna knock you right on the head\nYou better get yourself together\nPretty soon you're gonna be dead\nWhat in the world you thinking of\nLaughing in the face of love\nWhat on earth you tryin' to do\nIt's up to you, yeah you \n\nInstant Karma's gonna get you\nGonna look you right in the face\nBetter get yourself together darlin'\nJoin the human race\nHow in the world you gonna see\nLaughin' at fools like me\nWho in the hell d'you think you are\nA super star\nWell, right you are \n\nWell we all shine on\nLike the moon and the stars and the sun\nWell we all shine on\nEv'ryone come on \n\nInstant Karma's gonna get you\nGonna knock you off your feet\nBetter recognize your brothers\nEv'ryone you meet\nWhy in the world are we here\nSurely not to live in pain and fear\nWhy on earth are you there\nWhen you're ev'rywhere\nCome and get your share \n\nWell we all shine on\nLike the moon and the stars and the sun\nYeah we all shine on\nCome on and on and on on on\nYeah yeah, alright, uh huh, ah \n\nWell we all shine on\nLike the moon and the stars and the sun\nYeah we all shine on\nOn and on and on on and on \n\nWell we all shine on\nLike the moon and the stars and the sun\nWell we all shine on\nLike the moon and the stars and the sun\nWell we all shine on\nLike the moon and the stars and the sun\nYeah we all shine on\nLike the moon and the stars and the sun", "I'm the song Instant karma  of John Lennon");
//				Song s6 = new Song(6, "Lucy in the sky with diamonds", "John Lennon", 198, 60000000000000L, 1.2, "Picture yourself in a boat on a river\nWith tangerine trees and marmalade skies\nSomebody calls you, you answer quite slowly\nA girl with kaleidoscope eyes\n\nCellophane flowers of yellow and green\nTowering over your head\nLook for the girl with the sun in her eyes\nand she's gone\n\nLucy in the sky with diamonds\nLucy in the sky with diamonds\nLucy in the sky with diamonds, ah\n\nFollow her down to a bridge by a fountain\nWhere rocking horse people eat marshmallow pies\nEveryone smiles as you drift past the flowers\nthat grow so incredibly high\n\nNewspaper taxies appear on the shores\nWaiting to take you away\nClimb in the back with your head in the clouds\nand you're gone\n\nLucy in the sky with diamonds\nLucy in the sky with diamonds\nLucy in the sky with diamonds, ah\n\nPicture yourself on a train in a station\nWith plasticine porters with looking glass ties\nSuddenly someone is there at the turnstile\nThe girl with kaleidoscope eyes\n\nLucy in the sky with diamonds\nLucy in the sky with diamonds\nLucy in the sky with diamonds, ah\nLucy in the sky with diamonds\nLucy in the sky with diamonds\nLucy in the sky with diamonds, ah", "I'm the song Lucy in the sky with diamonds of John Lennon");
//				list.add(s1);
//				list.add(s2);
//				list.add(s3);
//				list.add(s4);
//				list.add(s5);
//				list.add(s6);
//				for (Song song : list){
//					SongInfoDTO songInfo = song.generateSongInfoDTO();
//					sid.add(songInfo);
//				}
//		
		return sid;
	}

	@Override
	public List<RecomendationDTO> showRecomendationList() {
		return null;
	}

}
